import * as server_ui from "@minecraft/server-ui";
import * as server from "@minecraft/server";
import * as realm_property from "../system/realm_property";
import * as derived_tools from "../system/derived_tools";
import * as native_tools from "../system/native_tools";
import * as achieve_plan from "../system/achieve_plan";
import * as math_tools from "../system/math_tools";
export function Vector(object) {
    const setOptions = {
        location: object.center(),
        maxDistance: 1.5,
    };
    const entitys = object.dimension.getEntities(setOptions);
    entitys.forEach(entity => {
        try {
            const Vector = entity.getViewDirection();
            entity.applyKnockback(Vector.x, Vector.z, (Math.abs(Vector.x) + Math.abs(Vector.z)) * 16, Math.abs(Vector.y) * 8);
            entity.addEffect('slow_falling', 60, { amplifier: 1, showParticles: false });
            entity.addEffect('resistance', 200, { amplifier: 31, showParticles: false });
            entity.addEffect('hunger', 200, { amplifier: 4, showParticles: false });
        }
        catch {
            entity.applyImpulse({ x: 0, y: Math.random() + 0.1, z: 0 });
        }
    });
}
;
export function Display(object) {
    const testEnergy = realm_property.AlterEnergy(object, 0, false);
    const showType = testEnergy[0] == true ? 'constant:pulse_rune_green' : 'constant:pulse_rune_red';
    derived_tools.DisplayChunkBoundary(object);
    native_tools.TrySpawnParticle(object.dimension, showType, math_tools.Vector.add(object, { x: 0.5, y: 0.5, z: 0.5 }));
}
;
export function Flame(object) {
    const getEntities = object.dimension.getEntitiesAtBlockLocation(math_tools.Vector.add(object, math_tools.Vector.CONSTANT_UP));
    getEntities.forEach(entity => entity.setOnFire(20, true));
}
;
export function RoadSignPresets(object) {
    const RoadSign = new Map();
    const player = object.dimension.getPlayers({ location: object.location, maxDistance: 8, closest: 1 })[0];
    if (!achieve_plan.ControlEventTrigger.EntityToken('诸界道标:使用冷却', player, 20))
        return;
    player.getDynamicPropertyIds().filter(id => id.startsWith('road_sign:')).forEach(id => native_tools.CompileSign(player, id, RoadSign));
    const name = Array.from(RoadSign.keys()).map(id => `§n§o§l§${Math.floor(Math.random() * 6)}` + id.split(':')[1]);
    const title = {
        text: "§9<§l 诸界道标 §r§9>"
    };
    const display = new server_ui.ActionFormData().title(title);
    name.forEach(info => display.button(info, "textures/物品贴图/魔法书籍/空间宝典"));
    if (name.length == 0)
        return player.onScreenDisplay.setTitle("§4暂无 §9道标信息§r");
    display.show(player).then(option => {
        if (option.canceled || option.selection == undefined)
            return;
        const value = Array.from(RoadSign.values());
        player.teleport(value[option.selection].location, { dimension: value[option.selection].dimension });
        server.system.runTimeout(() => player.playSound("mob.endermen.portal"), 5);
    });
}
;
